<?php
namespace app\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class StorehouseMaster extends Model{

	//设置表名NAME="warehouse_master";
	//设置表名
    const TABLE_NAME="warehouse_master";
    protected $goods_master = 'goods_master';
    protected $primaryKey = 'goods_id';
    protected $GoodsMaster = self::TABLE_NAME;
    public $timestamps = false;
    public function findStorehouseMaster($data)//查询
    {
        $sql = "SELECT
                    sm.storehouse_name,
                    cm.category_name,
                    gm.goods_name,
                    gm.goods_id,
                    gmm.color,
                    gmm.size,
                    sd.good_num,
                    sd.bad_num,
                    date_format(gm.stop_sales, \'%Y-%m-%d\') AS stop_sales,
                    date_format(now(), \'%Y-%m-%d\') AS date_time
                FROM
                    storehouse_master sm
                    LEFT JOIN `storehouse_detailed` sd ON sm.storehouse_id = sd.storehouse_id
                    LEFT JOIN goods_master gm ON sd.goods_id = gm.goods_id
                    LEFT JOIN goods_model gmm ON gm.goods_id = gmm.goods_id
                    LEFT JOIN `category_master` cm ON gm.category_id = cm.category_id
                WHERE
                    sd.storehouse_id = $data
                AND 
                    cm.category_id = 
                AND 
                    gm.goods_id = 
                AND 
                    gm.state = ";
        return DB::select($sql);

    }
}
